<?php

namespace Apps\AppApi\Method\Common;

use Apps\AppApi\Method\BaseMethod;
use Apps\Common\Models\BeautyParlorTagInfo;

/**
 * 获取标签列表
 * @author      545
 * @date        2016年1月11日
 * @version     1.1.2
 * @copyright   Copyright 2015 meelier.com
 */
class TagList extends BaseMethod
{
    public function run()
    {
        $data = BeautyParlorTagInfo::query()
        ->columns(['tag_id id', 'tag_title name'])
        ->where('tag_state = 1 AND parent_id = 0')
        ->orderBy('tag_id DESC')
        ->execute()
        ->toArray();
        
        
        foreach ($data as $k=>$v){
            $list[$k]['id'] = $v['id'];
            $list[$k]['name'] = $v['name'];
            $list[$k]['childtag'] = BeautyParlorTagInfo::query()
                                        ->columns(['tag_id id', 'tag_title name'])
                                        ->where('tag_state = 1 AND parent_id = :id:')
                                        ->bind(['id' => $v['id']])
                                        ->orderBy('tag_id DESC')
                                        ->execute()
                                        ->toArray();
         }
        
        $this->setResult($list);
    }
}